package com.leha.utils;

/**
 * Created by xiabin on 2017/6/29.
 */
public class MemUtils {
    public static long getUsedMemoryMB() {
        return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024;
    }

    public static long getFreeMemoryMB() {
        return (Runtime.getRuntime().maxMemory() - Runtime.getRuntime().totalMemory() + Runtime.getRuntime().freeMemory()) / 1048576;
    }

    public static long getTotalMemoryMB() {
        return Runtime.getRuntime().maxMemory() / 1048576;
    }

    public static String memoryInfo() {
        long freeMem = MemUtils.getFreeMemoryMB();
        long totalMem = MemUtils.getTotalMemoryMB();
        return "Free memory " + freeMem + " Mb of " + totalMem + " Mb";
    }
}
